'use strict';
module.exports = {
	/**
	 * 修改支付密码
	 * @url client/setting/kh/changePaymentPsw 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, psw, mobile, code } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		let info = await vk.baseDao.findByWhereJson({
			dbName: "opendb-verify-codes",
			whereJson: {
				mobile,
				code,
				type: 'resPayPsw',
				state: 0
			}
		});

		if (info == null) return {
			code: -1,
			msg: '验证码错误'
		}

		await vk.baseDao.updateById({
			dbName: "uni-id-users",
			id: uid,
			dataJson: { payment_psw: psw }
		})

		await vk.baseDao.updateById({
			dbName: "opendb-verify-codes",
			id: info._id,
			dataJson: { state: 1 }
		})

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
